package com.pxxy.mapper;

import com.pxxy.entity.Student;
import com.pxxy.mapper.impl.StudentMapperImpl;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

/******************
 * @Author yejf
 * @Description TODO
 */
public class UseStudentMapper {

    public static void main(String[] args) {
        //.
        try {
            final InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
            //0. 构建 SqlSessionFactory
            final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
            //1.构建 SqlSession
            final SqlSession sqlSession = factory.openSession();
            //创建 StudentMapper 对象
            StudentMapper studentMapper = new StudentMapperImpl(sqlSession);

            //就通可以通过对象来调方法
            final Student student = studentMapper.findById(106);
            System.out.println(student);
            // 查询所有：
            final List<Student> all = studentMapper.findAll();
            //
            System.out.println("--------------------------------");
            all.forEach(System.out::println);

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
